package com.dopies.bsdmall.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.dopies.BeeFramework.model.BaseModel;
import com.dopies.BeeFramework.model.BeeCallback;
import com.dopies.bsdmall.protocol.RECOMMENDUESRS;
import com.dopies.bsdmall.protocol.STATUS;
import com.external.androidquery.callback.AjaxStatus;

public class RecommendUsersModel extends BaseModel {
	public ArrayList<RECOMMENDUESRS> recommendList = new ArrayList<RECOMMENDUESRS>();

	public RecommendUsersModel(Context context) {
		super(context);
	}

	public void getRecommendList(String parent_id, final int i) {
		String url = ProtocolConst.RECOMMEND_USERS;
		BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() {
			@Override
			public void callback(String url, JSONObject jo, AjaxStatus status) {
				RecommendUsersModel.this.callback(url, jo, status);
				try {
					STATUS responseStatus = STATUS.fromJson(jo
							.optJSONObject("status"));
					if (responseStatus.succeed == 1) {
						JSONObject data = jo.optJSONObject("data");
						JSONArray recommendJsonArray = data
								.optJSONArray("users");
						recommendList.clear();
						if (null != recommendJsonArray
								&& recommendJsonArray.length() > 0) {
							recommendList.clear();
							for (int i = 0; i < recommendJsonArray.length(); i++) {
								JSONObject recommendJsonObject = recommendJsonArray
										.getJSONObject(i);
								RECOMMENDUESRS recommend = RECOMMENDUESRS
										.fromJson(recommendJsonObject);
								recommendList.add(recommend);
							}
						}
						RecommendUsersModel.this.OnMessageResponse(url, jo,
								status);
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
		};

		Map<String, String> params = new HashMap<String, String>();

		params.put("parent_id", parent_id);

		cb.url(url).type(JSONObject.class).params(params);
		aq.ajax(cb);

	}

}
